package com.faithnmn.learnenglishbc.receiver;


import com.faithnmn.learnenglishbc.service.InforService;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;

public class NetworkStateReceiver extends  BroadcastReceiver {
	private boolean firstConnect = true;
    @Override
    public void onReceive(Context context, Intent intent) {
    	Log.e("BSX","on receive networkStateReceiver");
    	ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
        if (activeNetInfo != null) {
            if(firstConnect) { 
            	firstConnect = false;
            	//trigger from here
            	Intent trigger = new Intent(context,InforService.class);
            	trigger.setAction("CH_NOTI");
            	context.startService(trigger);
            }
        } else {
            firstConnect= true;
        }
    }
};
